
/*
 * Copyright 2008 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * TODO make doc
 *
 * @author  Jonhnny Weslley
 * @version 1.00, 14/10/2008
 * @since   1.0
 */
public class IdFinder {

	public static void main(String[] args) throws IOException {
		String inputFilename = args.length > 0 ? args[0] : "alunos-noid.list";

		Map<Object, Object> alunos = new ConcurrentHashMap<Object, Object>();
		BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(inputFilename)));
		for (String line = reader.readLine();
			line != null;
			line = reader.readLine()) {
			alunos.put(alunos.size(), line);
		}

		Parser parser = new RegexBasedParser(alunos) {
			@Override protected boolean contains(String[] id_name) {
				return alunos.containsValue(id_name[1]);
			}
		};
		List<String[]> results = new ArrayList<String[]>();
		for (int step = 0; step <= Ranking.MAX && alunos.size() > 0; step += Ranking.PAGE_SIZE) {
			(new Resource(step, parser)).collectInto(results);
			for (String[] result : results) {
				System.out.printf("%s=%s (%s)\n", result[1], result[2], result[0]);
			}
			results.clear();
		}

	}

}
